package com.example.auv_660.command;

import com.example.auv_660.moduleload.DepthSensorLoad;
import com.example.auv_660.moduleload.ModuleLoad;
import com.example.auv_660.network.tcp.HFTCPBuild;
import com.example.auv_660.network.tcp.ModuleReadHandler;
import com.example.auv_660.network.tcp.ModuleWriteHandler;

import java.util.ArrayList;

public class AUVDepthSensorCommand extends AUVCommand {
    private ArrayList<ModuleLoad> moduleLoadArrayList;
    private static final String DEPTHSENSOR = "DepthSensorLoad";
    private int number = -1;

    public AUVDepthSensorCommand()
    {
        moduleLoadArrayList = HFTCPBuild.INSTANCE.getModuleInstance();
        number = getAUVModuleNumber(DEPTHSENSOR);
    }

    @Override
    public void writeCommand(String command) {
        if (number != -1)
        {
            ModuleWriteHandler depthSensorWriteHandler = moduleLoadArrayList.get(number).getWriterHandler();
            if (depthSensorWriteHandler != null)
            {
                depthSensorWriteHandler.sendCommandToModule(command);
            }
        }
    }

    @Override
    public void readCommand() {
        if (number != -1)
        {
            ModuleReadHandler depthSensorReadHandler = moduleLoadArrayList.get(number).getReadHandler();
            if (depthSensorReadHandler != null)
            {
                depthSensorReadHandler.getMessageFromModule();
            }
        }
    }

    public double getDepthAC()
    {
        if (number != -1)
        {
            return ((DepthSensorLoad) moduleLoadArrayList.get(number)).getDepthAC();
        }
        return 1000;
    }

    public boolean fixBasement()
    {
        return ((DepthSensorLoad) moduleLoadArrayList.get(number)).fixBasement();
    }
}
